import 'package:card_swiper/card_swiper.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:laos_mall/common/style/app_style.dart';
import 'package:laos_mall/common/style/extension_util.dart';
import 'package:laos_mall/common/widght/image_widget.dart';
import 'package:laos_mall/pages/main/catergory/sku/sku_item_widget.dart';
import 'package:laos_mall/pages/main/config.dart';
import 'logic.dart';

class ProductDetailPage extends StatelessWidget {
  ProductDetailPage({Key? key}) : super(key: key);

  final logic = Get.put(ProductDetailLogic());

  @override
  Widget build(BuildContext context) {
    return GetBuilder<ProductDetailLogic>(builder: (logic) {
      return Scaffold(
      appBar: AppBar(actions: [
        Image.asset('ic_money_cover'.toImgPath()).addContainer(width: 30.w,
            height: 30.w,
            padding: EdgeInsets.symmetric(horizontal: 5.w)).addGestureTap(() {
        }),
        Image.asset('ic_heart'.toImgPath(), width: 15.w,).addContainer(
            width: 30.w,
            height: 30.w,
            padding: EdgeInsets.symmetric(horizontal: 5.w),
            margin: EdgeInsets.only(right: 20.w, left: 10.w)).addGestureTap(
            logic.clickCollect),
      ],),
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text("${logic.model?.item?.product_name}",
            style: AppStyle.textStyle,),
          Swiper(itemCount: logic.model?.pic_list?.length ?? 1, itemBuilder: (context, index) {
            String ? url = logic.model?.pic_list?[index].pic_url;
            return ImageWidget(
             url: url, fit: BoxFit.contain);
          },pagination: SwiperPagination(builder: SwiperPagination.dots)).addContainer(height: ScreenUtil().screenWidth - 40.w,
              width: ScreenUtil().screenWidth - 40.w,
              color: Colors.transparent,
              margin: EdgeInsets.symmetric(vertical: 16.h)),
          Text("${Config.symbol}${logic.model?.item?.product_price}"),
          _buildSku(),
          _buildContent('product_des'.tr,
              Text("${logic.model?.item?.describe ?? ""}", style: AppStyle.textStyleLight,))
        ],).addSingleChildScrollView().addPadding(
          EdgeInsets.symmetric(horizontal: 20.w)),
      bottomNavigationBar: Container(height: 54.h + 27.h, child:
      Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Image.asset('ic_home'.toImgPath(), height: 15.w, fit: BoxFit
                  .fitHeight,).addContainer(
                  width: 30.w, height: 30.w, padding: EdgeInsets.symmetric(
                  horizontal: 2.w, vertical: 2.w)).addGestureTap(
                  logic.goToHome),
              Image.asset('ic_cart'.toImgPath(), width: 15.w,).addContainer(
                  width: 30.w, height: 30.w, padding: EdgeInsets.symmetric(
                  horizontal: 2.w, vertical: 2.w)).addGestureTap(
                  logic.goToCart),
            ],).addContainer(height: 54.h).addExpand(),
          VerticalDivider(width: 0.5, endIndent: 27.h,),
          AppButton.fullBtn(
              logic.addToCart, "add_to_cart".tr, style: AppButtonStyle.textBtn,
              padding: EdgeInsets.zero,
              size: Size(double.infinity, 54.h)).addExpand(),
          AppButton.fullBtn(
              logic.payNow, "pay_now".tr, style: AppButtonStyle.normal,
              padding: EdgeInsets.zero,
              size: Size(double.infinity, 54.h)).addExpand(),
        ],
      ).addContainer(height: 54.h,
          border: AppStyle.roundBorderExt(borderColor: AppColor.dividerColor))
        ,),
      );
    });
  }

  _buildContent(String title, Widget content) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text(title),
        SizedBox(height: 16.h,),
        content,
      ],).addContainer(color: Colors.transparent,
        margin: EdgeInsets.only(top: 12.h),
        width: double.infinity);
  }

  _buildSku() {
    return SkuItemWidget(selIndex: 0, isSkuPage: false,model: logic.model).addPadding(
        EdgeInsets.only(top: 10.h));
  }
}
